package com.music.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface LocalSongMapper {
    // 添加本地音乐
    @Insert("INSERT INTO local_songs (song_name, song_size, file_path, user_id, song_id) VALUES (#{song_name}, #{song_size}, #{file_path}, #{user_id}, #{song_id})")
    @Options(useGeneratedKeys = true, keyProperty = "local_song_id", keyColumn = "local_song_id")
    int addLocalSong(Map<String, Object> localSong);

    // 查询所有本地音乐
    @Select("SELECT * FROM local_songs")
    List<Map<String, Object>> showAllLocalSongs();

    // 根据本地音乐 ID 删除音乐
    @Delete("DELETE FROM local_songs WHERE local_song_id = #{local_song_id}")
    int deleteLocalSong(int localSongId);

    // 下载后音乐添加到本地音乐表中，逻辑与添加本地音乐相同
    default int addDownloadedSongToLocal(Map<String, Object> localSong) {
        return addLocalSong(localSong);
    }
}
